package com.theta.gateway.infra.common.constants;

import org.apache.commons.lang3.StringUtils;

import com.theta.gateway.infra.common.utils.StrUtil;


public class SystemConstant {
	
	/**
	 * 网关路由相关常量配置
	 */
	private static final String ROUTE_ID_PREFIX="routeId";
	private static final String ROUTE_PREDICATE_PATH_NAME="Path";
	private static final String ROUTE_URI_PREFIX="lb://";
	private static final String ROUTE_URI_PREFIX_HTTP="http://";
	private static final String ROUTE_URI_PREFIX_HTTPS="https://";
	private static final String ROUTE_PREDICATE_ARG_NAME="_genkey_";
	
	public static final String ROUTE_CODE_PREFIX="R";
	
	public static final String FEIGN_CLIENT_NAME_SSO="saas-sso-core";
	
//	public static final String SSO_AUTHEN_FILTER_NAME="SsoAuthentication";
	
	
	public static String genRouteId(Object routeId) {
		return StringUtils.join(ROUTE_ID_PREFIX,"-",routeId);
	}
	
	public static String getRoutePredicatePathName() {
		return ROUTE_PREDICATE_PATH_NAME;
	}
	
	public static String getGatewayRouteUri(String serviceId) {
		return StringUtils.join(ROUTE_URI_PREFIX,serviceId);
	}
	
	public static String getRoutePredicateArgName(int index) {
		return StringUtils.join(ROUTE_PREDICATE_ARG_NAME,index);
	}
	
	public static String genRouteUri(String uri) {
		if(StrUtil.isEmpty(uri))return StringUtils.EMPTY;
		if(uri.startsWith(ROUTE_URI_PREFIX_HTTP) || uri.startsWith(ROUTE_URI_PREFIX_HTTPS) || uri.startsWith(ROUTE_URI_PREFIX))
			return uri;
		else
			return StringUtils.join(ROUTE_URI_PREFIX,uri.startsWith("//")?uri.replaceFirst("//", ""):uri);
	}

}
